﻿<div class="page">
    <div id="header" class="bar">
        <div id="btnBack" class="btn-left">
            <span>Back</span>
        </div>
    </div>
    <div id="content">
        <div class="group">
            <label>Title:</label>
            <input type="text" id="txtTitle"/>
        </div>
        <div class="group">
            <div id="btnSave" class="btn">
                <span>Save</span>
            </div>
            <div id="btnSaveAndContinue" class="btn">
                <span>Save And Continue</span>
            </div>
        </div>
    </div>
</div>
<script language="javascript" type="text/javascript">
    (function () {
        var editingBlog = null;
        var service = new DbService();

        function save(callback) {
            var title = $("#txtTitle").val();
            if (title == "") {
                new nova.widgets.Toast("Title is required.").show();
                return;
            }
            editingBlog.title = title;
            service.saveBlog(editingBlog, callback);
        }

        $(document).ready(function () {
            editingBlog = nova.application.currentPage.blog;
            if (editingBlog.id > 0) {
                $("#btnSaveAndContinue").remove();
            }
            $("#txtTitle").val(editingBlog.title);
            nova.touch.bindClick("#btnBack", function () {
                nova.application.goBack();
            });
            nova.touch.bindClick("#btnSave", function () {
                save(function () {
                    nova.application.goBack();
                });
            });
            nova.touch.bindClick("#btnSaveAndContinue", function () {
                save(function () {
                    var page = new nova.Page("pages/editContent.html");
                    page.blog = editingBlog;
                    nova.application.gotoPage(page);
                });
            });
        });
    })();
</script>